package sto.orz.html.form;

import java.util.ArrayList;
import java.util.List;
import sto.orz.html.*;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.CompareToBuilder;

public class Form implements Comparable<Form> {
	private String action;

	private List<FormElement> elements = new ArrayList<FormElement>();

	private String name;

	private Style style = new Style();

	public Form(String name) {
		this.name = name;
	}

	public int compareTo(final Form other) {
		return new CompareToBuilder().append(name, other.name).append(action,
				other.action).append(style, other.style).append(elements,
				other.elements).toComparison();
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof Form))
			return false;
		Form castOther = (Form) other;
		return new EqualsBuilder().append(name, castOther.name).append(action,
				castOther.action).append(style, castOther.style).append(
				elements, castOther.elements).isEquals();
	}

	public String getAction() {
		return action;
	}

	public List<FormElement> getElements() {
		return elements;
	}

	public String getName() {
		return name;
	}

	public Style getStyle() {
		return style;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(name).append(action).append(style)
				.append(elements).toHashCode();
	}

	public void setAction(String action) {
		this.action = action;
	}

	public void setElements(List<FormElement> elements) {
		this.elements = elements;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setStyle(Style style) {
		this.style = style;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.appendSuper(super.toString()).append("name", name).append(
						"action", action).append("style", style).append(
						"elements", elements).toString();
	}
}
